In [1]:
# Load Biospytial modules and etc.
%matplotlib inline
import sys
sys.path.append('/apps')
import django
django.setup()
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
## Use the ggplot style
plt.style.use('ggplot')
In [2]:
from external_plugins.spystats import tools
%run ../testvariogram.py
In [3]:
section.shape
Out[3]:
In [4]:
minx,maxx,miny,maxy = getExtent(new_data)
In [5]:
maxy
Out[5]:
In [6]:
## Let's build the partition
N = 30
xp,dx = np.linspace(minx,maxx,N,retstep=True)
yp,dy = np.linspace(miny,maxy,N,retstep=True)
In [7]:
xx,yy = np.meshgrid(xp,yp)
In [8]:
coordinates_list = [ (xx[i][j],yy[i][j]) for i in range(N) for j in range(N)]
In [9]:
from functools import partial
tuples = map(lambda (x,y) : partial(getExtentFromPoint,x,y,step_sizex=dx,step_sizey=dy)(),coordinates_list)
In [10]:
len(tuples)
Out[10]:
In [11]:
chunks = map(lambda (mx,Mx,my,My) : subselectDataFrameByCoordinates(new_data,'newLon','newLat',mx,Mx,my,My),tuples)
In [12]:
len(chunks)
Out[12]:
In [13]:
## Here we can filter based on a threshold
threshold = 10
chunks_non_empty = filter(lambda df : df.shape[0] > threshold ,chunks)
In [14]:
len(chunks_non_empty)
Out[14]:
In [15]:
lengths = pd.Series(map(lambda ch : ch.shape[0],chunks_non_empty))
In [16]:
lengths.plot.hist()
Out[16]:
In [59]:
variograms =map(lambda chunk : tools.Variogram(chunk,'residuals1',using_distance_threshold=200000),chunks_non_empty[:30])
In [60]:
vars = map(lambda v : v.calculateEmpirical(),variograms)
vars = map(lambda v : v.calculateEnvelope(num_iterations=50),variograms)
In [118]:
envslow = pd.concat(map(lambda df : df[['envlow']],vars),axis=1)
envhigh = pd.concat(map(lambda df : df[['envhigh']],vars),axis=1)
variogram = pd.concat(map(lambda df : df[['variogram']],vars),axis=1)
In [119]:
lags = vars[0][['lags']]
In [120]:
meanlow = list(envslow.apply(lambda row : np.mean(row),axis=1))
meanhigh = list(envhigh.apply(np.mean,axis=1))
meanvariogram = list(variogram.apply(np.mean,axis=1))
results = pd.DataFrame({'meanvariogram':meanvariogram,'meanlow':meanlow,'meanhigh':meanhigh})
In [121]:
result_envelope = pd.concat([lags,results],axis=1)
In [110]:
meanvg = tools.Variogram(section,'residuals1')
In [111]:
meanvg.plot()
In [113]:
meanvg.envelope.columns
Out[113]:
In [122]:
result_envelope.columns
Out[122]:
In [123]:
result_envelope.columns = ['lags','envhigh','envlow','variogram']
In [124]:
meanvg.envelope = result_envelope
In [129]:
meanvg.plot(refresh=False)
In [127]:
meanvg.envelope
Out[127]:
In [ ]: